/* 使用正则表达式，实现split功能 */

#include<iostream>
#include<iterator>
#include<regex>
#include<vector>
#include<algorithm>
using namespace std;

int main(void)
{
    {
        string strSource("1 2 + 3 4 - *");
        regex wsRe(R"REG(\s+)REG");
        vector<string> vecStr;

        copy(sregex_token_iterator(strSource.begin(), strSource.end(), wsRe, -1),
            sregex_token_iterator(),
            back_inserter(vecStr));

        for_each(vecStr.begin(), vecStr.end(), [](auto s) -> void {cout<< s << " ";});
        cout<<endl;
    }
	
    {
        const string strSource(R"(<a href="http://www.baidu.com" class="foo_baidu">baidu</a> )"
                                  R"(<a href="http://www.126.com" class="foo_126">126</a> )"
                                  R"(<a href="http://www.taobao.com" class="foo_taobao">taobao</a> )");
        const regex link_re(R"REG(<a href="([^"]+)" class="([^"]+)">([^<]+)</a>)REG");

        sregex_token_iterator it(strSource.begin(), strSource.end(), link_re, {1, 2, 3});
        sregex_token_iterator itEnd;
        while (it != itEnd)
        {
            std::cout<< "address = " << *it++ << ", foo = " << *it++ << ", company = " << *it++ << std::endl;
        }
    }


}
